// pages/order/order.js
var util = require('../../utils/network.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
      _num:'1',
      _index:'0',
      order:[],
      bShow: false,//类型筛选
      bHide: false,//时间筛选
      bShade: false,//遮罩层
      color:'#8F8F8F',//筛选类型文字颜色
      currentItemId:0,
      targetId:0,
      typeList:[
          { text: "全部", id: 0 },
          { text: "汽车票", id: 1 },
          { text: "景点巴士", id: 2 },
          { text: "机场巴士", id: 3 },
          { text: "校园巴士", id: 4 },
          { text: "城际用车", id: 5 },
          { text: "定制包车", id: 6 },
          { text: "门票", id: 7 },
          { text: "火车票", id: 8 }
      ],
      dateList: [
          { text: "全部", id: 0 },
          { text: "一天", id: 1 },
          { text: "三天", id: 2 },
          { text: "一周", id: 3 },
          { text: "一个月", id: 4 },
          { text: "三个月", id: 5 }
      ]
  },
  clickNum: function (e) {
      this.setData({
          _index: '0',
          bShow: false,//类型筛选
          bHide: false,//时间筛选
          bShade: false,//遮罩层
          _num: e.target.dataset.num
      })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      var that=this
      var token = util.token
      if (that.data._num=='1'){
          wx.request({
              url: util.main + '/bus/interface/order/getorderlist',
              data:{
                  "token":token,
                  "filtertype":2,
                  "page":1,
                  "size":10
              },
              method:"GET",
              success:function(res){
                  console.log(res)
                  if (res.statusCode==200){
                      that.setData({
                          order: res.data.orderinfos
                      })
                  }
              }
          })
      }
  },
// 类型筛选
    typeFilter:function(e){
        this.setData({
            bShow: true,
            bShade: true,
            bHide:false,
            _index: e.target.dataset.index
        })
    },
    typeChange:function(e){
        var that=this
        var token = util.token
        that.setData({
            currentItemId: e.target.dataset.index
        })
        if (that.data._num == '1') {
            if (that.data.currentItemId == 1) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype":"bus",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 2){
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "jdbs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 3) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "bs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 4) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "xybs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 5) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "cjyc",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 6) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "dzbc",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 7) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "ordertype": "mp",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            }
        } else if (that.data._num == '2') {
            if (that.data.currentItemId == 1) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "bus",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 2) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "jdbs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 3) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "bs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 4) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "xybs",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 5) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "cjyc",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 6) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "dzbc",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.currentItemId == 7) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "ordertype": "mp",
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            }
        }
    },
    // 时间筛选
    timeFilter: function (e) {
        this.setData({
            bHide: true,
            bShade: true,
            bShow:false,
            _index: e.target.dataset.index
        })
    },
    timeChange: function (e) {
        var that = this
        var token = util.token
        that.setData({
            targetId: e.target.dataset.index
        })
        if (that.data._num == '1') {
            if (that.data.targetId == 1) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "timeperiod": 1,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 2) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "timeperiod": 2,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 3) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "timeperiod": 3,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 4) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "timeperiod": 4,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 5) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 2,
                        "page": 1,
                        "timeperiod": 5,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            }
        } else if (that.data._num == '2') {
            if (that.data.targetId == 1) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "timeperiod": 1,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 2) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "timeperiod": 2,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 3) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "timeperiod": 3,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 4) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "timeperiod": 4,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            } else if (that.data.targetId == 5) {
                wx.request({
                    url: util.main + '/bus/interface/order/getorderlist',
                    data: {
                        "token": token,
                        "filtertype": 1,
                        "page": 1,
                        "timeperiod": 5,
                        "size": 10
                    },
                    method: "GET",
                    success: function (res) {
                        if (res.statusCode == 200) {
                            that.setData({
                                order: res.data.orderinfos
                            })
                        }
                    }
                })
            }
        }
    },
    // 点击遮罩层
    shadeHide:function(){
        this.setData({
            bHide: true,
            bShow: true,
            bShade: false
        })
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})